/////////////////////////////////////////////////////////////////////////////
// Filename: Vertex.h
// Description: Vertex class
/////////////////////////////////////////////////////////////////////////////

#ifndef VERTEX_H
#define VERTEX_H

#include "Vector3.h"
#include "Color.h"
#include "Matrix4.h"

class Vertex{
public:
	Vector3 position;
	Vector3 view_position;
	Vector3 normal;
	Vector3 view_normal;
	Color illumination;

public:
	Vertex(){}
	Vertex(Vector3 p){position=p;}
	Vertex(float x, float y, float z){position=Vector3(x,y,z); }

	void transform(Matrix4 m){
		view_position=m*position;

		//If you do non-isotropic scaling (sx!=sy etc) you must transform the normal
		//according to a "well known" :) theorem of tensor algebra n=m.inv().transpose()
		//We most probably don't do that, so I will not bother you with this.
		//So we just go on as normal, which works fine for isotropic scaling and rotations. 
		//Note also that w is explicitly set to 0 -we don't want normals to be affected by translations.  
		view_normal=m*Vector3h(normal,0);
		view_normal.normalize();
	}
};

#endif

/////////////////////////////////////////////////////////////////////////////
//                               END OF FILE                               //
/////////////////////////////////////////////////////////////////////////////